package com.ejia.server;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.ejia.dao.BaseDao;
import com.ejia.pojo.fangkong;
import com.ejia.pojo.house;
import com.ejia.pojo.money;
import com.ejia.pojo.user;

public class HouseService {

	public static boolean yzxxadd(String hname,int parentid) {
		String sql="insert into tb_house(hname,parentid) values(?,?)";
		return new BaseDao().execute(sql,hname,parentid);
	}
	public static boolean updateinfo(String address,String hid) {
		return new BaseDao().execute("update tb_house set address=? where hid=?", address,hid);
	}
	
	public static ArrayList<house> find(String hname) {
		String sql="select hid from tb_house where hname=?";
		ResultSet rSet=BaseDao.query(sql,hname);
		ArrayList<house> houses= new ArrayList<>();
		house house=null;
		try {
			while (rSet.next()) {
				house=new house();
				house.setHid(rSet.getInt("hid"));
				houses.add(house);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return houses;
	}
	
	
	public static int hid(String hname,int parentid) {
		String sql="select hid from tb_house where hname=? and parentid=?";
		BaseDao baseDao=new BaseDao();
		ResultSet rSet=baseDao.query(sql,hname,parentid);
		try {
			while (rSet.next()) {
				return rSet.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
	}
}
